package cn.jisol.ngame.actions.statesync.client;

import cn.jisol.ngame.actions.statesync.CNStateSyncAction;
import cn.jisol.ngame.actions.statesync.entity.FilterSyncData;
import cn.jisol.ngame.client.DefaultNClient;
import cn.jisol.ngame.client.tool.QueueNClient;
import cn.jisol.ngame.proto.message.NGameMessageOuterClass;
import cn.jisol.ngame.rpc.CNGameCActionValue;
import cn.jisol.ngame.rpc.NGameRPC;
import com.google.protobuf.InvalidProtocolBufferException;
import lombok.Getter;
import lombok.Setter;

import javax.websocket.Session;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.Objects;

/**
 * 状态同步客户端
 */
@Getter
@Setter
public class NStateSyncClient extends DefaultNClient {
    
    //当前角色
    Role role;
    
    //同步过滤器
    ArrayList<FilterSyncData> filters = new ArrayList<FilterSyncData>();
    
    @CNGameCActionValue
    public CNStateSyncAction cnStateSyncAction;
    
    public NStateSyncClient(Session session){
        super(session.getId(),session);
    }
    
    public NStateSyncClient(String uuid, Session session) {
        super(uuid, session);
    }
    
    public enum Role{
        OWNER("owner"),//房主
        PLAYER("player"); //玩家
        
        String _value;
        
        Role(String value){
            this._value = value;
        }
        
        @Override
        public String toString() {
            return this._value;
        }
        
        public static Role fromStatus(String role){
            if(Objects.nonNull(role)){
                return EnumSet.allOf(Role.class).stream()
                    .filter(str -> str.toString().equals(role))
                    .findAny()
                    .orElseThrow(() -> new IllegalArgumentException("未找到枚举:"+role));
            }else{
                return null;
            }
        }
    }
    
}
